// 权限问题后期增加
import { get, post } from '@/utils/http/axios';
import { UserState } from '@/store/modules/user/types';

// import axios from 'axios';
enum URL {
  login = '/system/user/login',
  logout = '/system/user/login-out',
  profile = '/user/profile',
  register = '/register',
  getInfo = '/system/user/getInfo',
  forceLogout = '/system/user/login-out-force',
}
interface LoginRes {
  token: string;
}

export interface LoginData {
  username: string;
  password: string;
  code: string;
  loginCode: string;
}

const getUserProfile = async () => get<UserState>({ url: URL.profile });

// 登录
const login = async (obj: LoginData) => {
  const data = {
    userId: obj.username,
    passwd: obj.password,
    loginCode: obj.code,
    imgCode: obj.loginCode,
  };
  return post({
    url: URL.login,
    // outErrortips:true,
    data: data,
  });
};

// 登出
const logout = async () => {
  return post<LoginRes>({
    url: URL.logout,
  });
};

// 强制登出
const logoutforce = () => {
  post({ url: URL.forceLogout });
};

// 注册方法
const register = async (data) => {
  return post({
    url: URL.register,
    headers: {
      isToken: false,
    },
    method: 'post',
    data: data,
  });
};

// 获取用户详细信息
const getInfo = async () => {
  return get({
    url: URL.getInfo,
  });
};
export { getUserProfile, logout, login, register, getInfo, logoutforce };
